from urldb.model import DeclarativeBase
from sqlalchemy import Column, ForeignKey, Index, Integer, String, DateTime
from sqlalchemy.sql import func
from sqlalchemy.orm import relation, backref

class Url(DeclarativeBase):
    __tablename__ = 'url'
    id = Column(Integer, primary_key=True)
    url = Column(String)
    host = Column(String)
    created = Column(DateTime, default=func.current_timestamp())
    updated = Column(DateTime, default=func.current_timestamp())


class UrlParam(DeclarativeBase):
    __tablename__ = 'url_param'

    id = Column(Integer, primary_key=True)
    name = Column(String)
    value = Column(String)
    url_id = Column(
        Integer,
        ForeignKey(Url.id),
        nullable=False
    )
    url = relation(Url, backref=backref('params', order_by=id))
